﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Dev2419a_LunarLander3D
{
    class Introducao // Classe responsável pelo carregamento do vídeo de início
    {
        public Video videoIntro;
        public VideoPlayer mediaPlayer = new VideoPlayer();
        private SpriteFont fonte;
        private float count;

        public Introducao(ContentManager Content)
        {
            videoIntro = Content.Load<Video>("video"); // Video de teste, PRECISA SER TROCADO!!!! 
            this.fonte = Content.Load<SpriteFont>("CountDown");
        }
        
        public void Update(GameTime gameTime, KeyboardState keyboard, KeyboardState oldKeyboard)
        {
            mediaPlayer.Play(videoIntro);
            if (keyboard.IsKeyDown(Keys.Enter))
            {
                mediaPlayer.Stop();
            }

            //count -= gameTime.ElapsedGameTime.Milliseconds / 1000;
            count = (int) (8.9f - ((float)gameTime.TotalGameTime.Seconds + ((float)(gameTime.TotalGameTime.Milliseconds) / 1000)));
            if (count < 0) { count = 0; }
             

        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 viewport)
        {
            if (gameTime.TotalGameTime.Seconds > 9)
            {
                spriteBatch.Draw(mediaPlayer.GetTexture(), new Rectangle(0, 0, (int)viewport.X, (int)viewport.Y), Color.White);
            }
            else
            {
                //spriteBatch.DrawString(fonte, count.ToString(), new Vector2(454 - fonte.MeasureString(count.ToString()).X, 20), Color.Yellow);
                spriteBatch.DrawString(fonte, count.ToString(), new Vector2(300, 120), Color.Green);
            }
        }
    }
}
